home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume89 / workbnch / flist12.3 < prev    next >
Text File  |  1989-03-15  |  27KB  |  1,037 lines

  1. Path: xanth!ames!mailrus!ulowell!page
  2. From: page@swan.ulowell.edu (Bob Page)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v89i051:  flist - scrollable cli and directory lister v1.2, Part03/03
  5. Message-ID: <12230@swan.ulowell.edu>
  6. Date: 15 Mar 89 17:23:23 GMT
  7. Organization: University of Lowell, Computer Science Dept.
  8. Lines: 1026
  9. Approved: page@swan.ulowell.edu
  10.  
  11. Submitted-by: alliant!mistress!berry (Steve -Raz- Berry)
  12. Posting-number: Volume 89, Issue 51
  13. Archive-name: workbench/flist12.3
  14.  
  15. #    This is a shell archive.
  16. #    Remove everything above and including the cut line.
  17. #    Then run the rest of the file through sh.
  18. #----cut here-----cut here-----cut here-----cut here----#
  19. #!/bin/sh
  20. # shar:    Shell Archiver
  21. #    Run the following text with /bin/sh to create:
  22. #    sort.c
  23. #    ttyicon.c
  24. #    ttyio.c
  25. # This archive created: Wed Mar 15 12:12:50 1989
  26. cat << \SHAR_EOF > sort.c
  27. /* 
  28.  
  29.     The Sorting routines live here.
  30.     I used the quick sort algorithm as implimemted by Manx to sort a
  31.     list of indices, and then I rearranged the data to conform to the
  32.     sorted list. In order to do the sort, there must be one free element
  33.     available in the array.
  34.  
  35.     Written by Steve (Raz) Berry.
  36.  
  37.     1/8/89
  38. */
  39.  
  40. #include "flist.h"
  41. #include <libraries/arpbase.h>
  42.  
  43. extern long (*finfo[MAXDIR])[4];  
  44. extern char (*fname[MAXDIR])[FCHARS];
  45. extern char (*comm[MAXDIR])[FCHARS];
  46. extern char (*fstring[MAXDIR])[LEN_DATSTRING];
  47. extern char (*ftime[MAXDIR])[LEN_DATSTRING];
  48. extern long numfiles, top, row, line;
  49. extern struct AnchorPath *ap;
  50. extern char strbuf[256];
  51.  
  52. extern void swap();
  53. long lastsort = -1;
  54.  
  55. sort(which)
  56. int which;
  57. {
  58.     if (numfiles > MAXDIR -1) {
  59.         auto_req("Can't sort list - No space");
  60.         return;
  61.     }
  62.  
  63.     switch (which) {
  64.         case 0:
  65.             sortname();
  66.             lastsort = 0;
  67.             break;
  68.         case 1:
  69.             sortsize();
  70.             lastsort = 1;
  71.             break;
  72.         case 2:
  73.             sortdate();
  74.             lastsort = 2;
  75.             break;
  76.         case 3:
  77.             sortpattern();
  78.             break;
  79.         case 4:
  80.             sortday();
  81.             lastsort = 4;
  82.             break;
  83.     }
  84. }
  85.  
  86. cmp(s1,s2)
  87. long *s1, *s2;
  88. {
  89.     return Strcmp(fname[*s1], fname[*s2]);
  90. }
  91.  
  92. sortname()
  93. {
  94.     long list[MAXDIR];
  95.     register long i;
  96.  
  97.     for (i = 0;i<numfiles;i++)
  98.         list[i] = i;
  99.  
  100.     qsort(list, numfiles, 4L, cmp);
  101.  
  102.     sortme(list);
  103. }
  104.  
  105. cmp1(s1,s2)
  106. long *s1,*s2;  
  107. {
  108.     return ((*finfo[*s1])[2] > (*finfo[*s2])[2]) ? 1 : 
  109.            ((*finfo[*s1])[2] < (*finfo[*s2])[2]) ? -1 : 0;
  110. }
  111.  
  112. sortsize()
  113. {
  114.     long list[MAXDIR];
  115.     register long i;
  116.  
  117.     for (i = 0;i < numfiles;i++)
  118.         list[i] = i;
  119.  
  120.     qsort(list, numfiles, 4L, cmp1);
  121.  
  122.     sortme(list);
  123. }
  124.  
  125. cmp2(s1,s2)
  126. long *s1, *s2;
  127. {
  128.     return Strcmp(ftime[*s1], ftime[*s2]);
  129. }
  130.  
  131. sortdate()
  132. {
  133.     long list[MAXDIR]; 
  134.     register long i;
  135.     
  136.     for (i = 0;i < numfiles;i++)
  137.         list[i] = i;
  138.  
  139.     qsort(list, numfiles, 4L, cmp2);
  140.  
  141.     sortme(list);
  142. }
  143.  
  144. cmp3(s1,s2)
  145. long *s1, *s2;
  146. {
  147.     return Strcmp(fstring[*s1], fstring[*s2]);
  148. }
  149.  
  150. sortday()
  151. {
  152.     long list[MAXDIR]; 
  153.     register long i;
  154.     
  155.     for (i = 0;i < numfiles;i++)
  156.         list[i] = i;
  157.  
  158.     qsort(list, numfiles, 4L, cmp3);
  159.  
  160.     sortme(list);
  161. }
  162.  
  163. /* 
  164.     Here we sort by pattern... actually we just reget the directory based
  165.     on the input string.
  166. */
  167.  
  168. long sortpattern()
  169. {
  170.     char buf[256];
  171.     struct Window *strptr;
  172.     long rc;
  173.  
  174.     strbuf[0] = '\0';
  175.     strptr = make_gadget("Enter search Pattern");
  176.  
  177.     if (strptr == NULL) {
  178.         auto_req("Couldn't open Requestor!");
  179.         return BAD_COMMAND;
  180.     }
  181.  
  182.     drawcur();
  183.  
  184.     wait_for_event(strptr);
  185.  
  186.     blankcur();
  187.  
  188.     if (strbuf[0] == '\0')
  189.         return NULL;
  190.  
  191.     rc = FindFirst(strbuf,ap);
  192.  
  193.     if (rc == NULL){
  194.         Fillarray();    /* fill the arrays with the names and info */
  195.         top = 0;
  196.         row = 0;    
  197.         line = 0;
  198.     }
  199.     else {
  200.         if (rc != ERROR_NO_MORE_ENTRIES){
  201.             sprintf(buf,"Bad pattern -%s- !",strbuf);
  202.             auto_req(buf);
  203.             FindFirst("*",ap);
  204.             Fillarray();
  205.             top = 0;
  206.             row = 0;    
  207.             line = 0;
  208.         } else
  209.             numfiles = 0;
  210.     }
  211.  
  212.     return rc;
  213. }
  214.  
  215. /*  Here's the deal... Now that I have the list of indices all sorted,
  216.     I figured that arranging the list to match the indices would be
  217.     simple. WRONG. This was the hardest part by far. Next time I will
  218.     arrange my arrays as structures and sort them in place.
  219.     I'll probably also use a Heapsort routine 
  220.     (it's a better general purpose routine) as well. */
  221.  
  222. /* More sorting for the resultant list */
  223.  
  224. find(index, list)
  225. long list[MAXDIR];
  226. {
  227.     register long i;
  228. #ifdef DEBUG
  229.     if (index <0){
  230.         auto_req("index of -1!");
  231.         return 0;
  232.     }
  233. #endif
  234.     for (i=0;index != list[i];i++);
  235.  
  236.     return i;
  237. }
  238.  
  239. swapall(one, two)
  240. long one, two;
  241. {
  242.     swap(&finfo[one], &finfo[two]);
  243.     swap(&fname[one], &fname[two]);
  244.     swap(&comm[one], &comm[two]);
  245.     swap(&fstring[one], &fstring[two]);
  246.     swap(&ftime[one], &ftime[two]);
  247. }
  248.  
  249. /* This routine actually rearanges the list into the proper order */
  250.  
  251. sortme(list)
  252. long list[MAXDIR];
  253. {
  254.     register long sa, pos, i;
  255.     long first = -1,index;
  256.  
  257.     sa = numfiles;
  258.     index = 0;
  259.  
  260.     while(1) {
  261.  
  262.         for(i=0;((list[i] == -1) || (list[i] == i)) && (i < numfiles);i++);
  263.  
  264.         if (i >= numfiles)
  265.             break;
  266.         index = i;
  267.         first = -1;
  268.  
  269.         for (i=0;i<numfiles;i++) {      /* prime the pipe */
  270.             pos = find(index, list);
  271.             if (pos != index) {
  272.                 if (first == -1)
  273.                     first = index;
  274.                 swapall(index, pos);
  275.                 swapall(index, sa);
  276.                 list[pos] = -1;
  277.                 index = pos;
  278.             } else
  279.                 list[index++] = -1;
  280.             if (first != -1)
  281.                 break;
  282.         }
  283.  
  284.         for (i=0;pos != first;i++) {    /* follow the thread to the end */
  285.             pos = find(index, list);
  286.             swapall(sa, pos);
  287.             list[pos] = -1;
  288.             index = pos;
  289.         }
  290.     }
  291. }
  292. SHAR_EOF
  293. cat << \SHAR_EOF > ttyicon.c
  294. /*
  295.  *          Iconify the Flist window using Leo Schwab's iconify() routine.
  296.  *
  297.  */
  298.  
  299.  
  300. #include <intuition/intuition.h>
  301. #include "icon/iconify.h"
  302.  
  303. extern struct Screen *scrptr;
  304.  
  305. UWORD               flicon_data[] = {
  306.  
  307.      /* BitPlane #0 */
  308.  
  309.      0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 
  310.      0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xC000, 
  311.      0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xC000, 
  312.      0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xC000, 
  313.      0x7C00, 0x0000, 0x0000, 0x000F, 0xC000, 
  314.      0x7C00, 0x0000, 0x0000, 0x000F, 0xC000, 
  315.      0x7C1F, 0xE783, 0x8001, 0x800F, 0xC000, 
  316.      0x7C0E, 0xE380, 0x0003, 0x800F, 0xC000, 
  317.      0x7C0E, 0x0387, 0x87E7, 0xE00F, 0xC000, 
  318.      0x7C0F, 0x8383, 0x8E03, 0x800F, 0xC000, 
  319.      0x7C0E, 0x0383, 0x87C3, 0x800F, 0xC000, 
  320.      0x7C0E, 0x0383, 0x80E3, 0xE00F, 0xC000, 
  321.      0x7C1F, 0x07C7, 0xCFC1, 0xC00F, 0xC000, 
  322.      0x7C00, 0x0000, 0x0000, 0x000F, 0xC000, 
  323.      0x7C00, 0x0000, 0x0000, 0x000F, 0xC000, 
  324.      0x7C00, 0x0000, 0x0000, 0x000F, 0xC000, 
  325.      0x7C00, 0x0000, 0x1E00, 0x000F, 0xC000, 
  326.      0x7C00, 0x0000, 0x0E00, 0x000F, 0xC000, 
  327.      0x7C00, 0x07EE, 0x7FC0, 0x000F, 0xC000, 
  328.      0x7C00, 0x0E0F, 0xFFE0, 0x000F, 0xC000, 
  329.      0x7C00, 0x07CF, 0xFEE0, 0x000F, 0xC000, 
  330.      0x7C00, 0x00E7, 0xEEE0, 0x000F, 0xC000, 
  331.      0x7C00, 0x0FC7, 0xE7C0, 0x000F, 0xC000, 
  332.      0x7C00, 0x0000, 0x0000, 0x000F, 0xC000, 
  333.      0x7C00, 0x0000, 0x0000, 0x000F, 0xC000, 
  334.      0x7C00, 0x0000, 0x0000, 0x000F, 0xC000, 
  335.      0x7C00, 0x0000, 0x0000, 0x000F, 0xC000, 
  336.      0x7C00, 0x0000, 0x0000, 0x000F, 0xC000, 
  337.      0x7C00, 0x0000, 0x0000, 0x000F, 0xC000, 
  338.      0x7C00, 0x0000, 0x0000, 0x000F, 0xC000, 
  339.      0x7C00, 0x0000, 0x0000, 0x000F, 0xC000, 
  340.      0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xC000, 
  341.      0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xC000, 
  342.      0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xC000, 
  343.      0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 
  344.  
  345.      /* BitPlane #1 */
  346.  
  347.      0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 
  348.      0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xC000, 
  349.      0x4000, 0x0000, 0x0000, 0x0000, 0x4000, 
  350.      0x4000, 0x0000, 0x0000, 0x0000, 0x4000, 
  351.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  352.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  353.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  354.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  355.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  356.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  357.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  358.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  359.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  360.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  361.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  362.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  363.      0x43FF, 0xFFFF, 0xE1FF, 0xFFF0, 0x4000, 
  364.      0x43FF, 0xFFFF, 0xF1FF, 0xFFF0, 0x4000, 
  365.      0x43FF, 0xF811, 0x803F, 0xFFF0, 0x4000, 
  366.      0x43FF, 0xF1F0, 0x001F, 0xFFF0, 0x4000, 
  367.      0x43FF, 0xF830, 0x011F, 0xFFF0, 0x4000, 
  368.      0x43FF, 0xFF18, 0x111F, 0xFFF0, 0x4000, 
  369.      0x43FF, 0xF038, 0x183F, 0xFFF0, 0x4000, 
  370.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  371.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  372.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  373.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  374.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  375.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  376.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  377.      0x43FF, 0xFFFF, 0xFFFF, 0xFFF0, 0x4000, 
  378.      0x4000, 0x0000, 0x0000, 0x0000, 0x4000, 
  379.      0x4000, 0x0000, 0x0000, 0x0000, 0x4000, 
  380.      0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xC000, 
  381.      0x0000, 0x0000, 0x0000, 0x0000, 0x0000
  382.      };
  383.  
  384. UWORD   cursor_img[] = {
  385.         0xff00,0xff00,
  386.         0xff00,0xff00,
  387.         0xff00,0xff00,
  388.         0xff00,0xff00,
  389.         0xff00
  390.         };
  391.  
  392. struct Image               cursor_image = {
  393.      0, 0, 8, 9, 1, cursor_img, 0x0, 0x4, NULL
  394.      };
  395.  
  396. UWORD   cursor_empty[] = {
  397.         0x0000,0x0000,
  398.         0x0000,0x0000,
  399.         0x0000,0x0000,
  400.         0x0000,0x0000,
  401.         0x0000
  402.         };
  403.  
  404. struct Image               cursor_blank = {
  405.      0, 0, 8, 9, 1, cursor_empty, 0x0, 0x0, NULL
  406.      };
  407.  
  408. struct Image               flicon_image = {
  409.      0, 0, 67, 35, 2, NULL, 0x3, 0x0, NULL
  410.      };
  411.  
  412. extern struct Process *myproc;
  413. extern struct Window *winptr;
  414.  
  415. int tticon()
  416. {
  417.     static UWORD iconX = 0, iconY = 0;
  418.  
  419.     if(scrptr->FirstWindow->NextWindow != NULL) {
  420.         auto_req("Kill all other Applications first");
  421.         return FALSE;
  422.     }
  423.  
  424.     /* hide the window, display the icon, then redisplay the window */
  425.  
  426.     myproc->pr_WindowPtr = (APTR)-1; 
  427.     tthide(FALSE);     /* not resizing */
  428.  
  429.     flicon_image.ImageData = &flicon_data[0];
  430.     iconify(&iconX, &iconY, flicon_image.Width, flicon_image.Height, NULL,
  431.          &flicon_image, (int) ICON_IMAGE); /* iconify     */
  432.  
  433.     ttshow(FALSE);     /* no resize */
  434.     myproc->pr_WindowPtr = winptr; 
  435.     return TRUE;
  436. }
  437. SHAR_EOF
  438. cat << \SHAR_EOF > ttyio.c
  439. /*
  440.         This is the I/O stuff for Flist... Inspired by the Mg2a
  441.         project. 
  442.         
  443.         Written by Stephen W. Berry. 8/19/88
  444. */
  445.  
  446. #include <libraries/arpbase.h>
  447. #include "flist.h"
  448.  
  449. /*
  450.  * External Amiga functions.
  451.  */
  452.  
  453. extern     LONG       AbortIO();
  454. extern     LONG       CloseDevice();
  455. extern     struct     IOStdReq     *CreateStdIO();
  456. extern     int        OpenConsole();
  457. extern     struct     Window          *OpenWindow();
  458. extern     LONG       RawKeyConvert();
  459. extern     top;
  460.  
  461. /* extern Flist variables */
  462.  
  463. extern struct NewWindow *winptr;
  464. extern struct Window mywin;
  465. extern struct NewScreen *scrptr;
  466. extern struct Screen scr;
  467. extern struct Menu fmenu;
  468. extern struct Gadget pg;
  469. extern struct RastPort *rp;
  470. extern struct Image cursor_image;
  471. extern struct Image cursor_blank;
  472. extern Enable_Abort;
  473. extern struct FileLock *lock, *olddir;
  474. extern char (*fname[MAXDIR])[FCHARS];
  475. extern long (*finfo[MAXDIR])[4];
  476. extern short remember;
  477.  
  478. /* Some external functions */
  479.  
  480. extern void swapdir(), parent();
  481. extern long DoDOS(), spawnproc(), kill(), changedir();
  482.  
  483. /* Global variables */
  484.  
  485. struct Device *ConsoleDevice;
  486. struct IOStdReq ConsoleReq;
  487. struct InputEvent RawKeyEvent = {NULL,IECLASS_RAWKEY,0,0,0};
  488.  
  489. #define BUFSIZ 10
  490.  
  491. UBYTE KeyBuffer[BUFSIZ];
  492.  
  493. struct IntuiText input = {
  494.         TEXTCOLOR,0,  /* Front & Back pen */
  495.         JAM2,   /* Drawmode */
  496.         0,0,    /* Left, Top */
  497.         NULL,   /* Font */
  498.         KeyBuffer,
  499.         NULL    /* Next text */
  500.         };
  501.  
  502. char conline[256];
  503. char titlestr[80];
  504. long row = 0,collum = 0,line = 0,first = 0;
  505.  
  506. void ttclose(),tthide(),ttshow();
  507.  
  508. /*
  509.  * Iconify Flist's window using tthide(), iconify(), and ttshow().
  510.  */
  511.  
  512.  
  513. VOID
  514. tthide(resize)
  515. int resize;
  516. {
  517.      if (resize == TRUE) {               /* if we're resizing,     */
  518.           mywin.LeftEdge = winptr->LeftEdge; /* use current window size */
  519.           mywin.TopEdge = winptr->TopEdge;
  520.           mywin.Width = winptr->Width;
  521.           mywin.Height = winptr->Height;
  522.      }
  523.      ttclose();                    /* reset to zero     */
  524. }
  525.  
  526. VOID
  527. ttshow(resize)
  528. int resize;
  529. {
  530.      openstuff();
  531.      SetMenuStrip(winptr, &fmenu);
  532.      Enable_Abort = 1;          
  533. }
  534.  
  535. VOID
  536. ttclose()
  537. {
  538.      ClearMenuStrip(winptr);
  539.      CloseWindowSafely(winptr,NULL);
  540.      CloseScreen(scrptr);
  541.      winptr = NULL; scrptr = NULL;
  542.      Enable_Abort = 0;
  543. }
  544.  
  545. extern long numfiles, lastsort;
  546.  
  547. refresh()
  548. {
  549.     char buf[100], buf1[200];
  550.     remember = -10;
  551.  
  552.     collum = 0;
  553.     if (row+1 > numfiles && row+2 == numfiles) {
  554.         row--;
  555.         line--;
  556.     } else 
  557.         if (row > numfiles) {
  558.             top = 0;
  559.             row = 0;    
  560.             line = 0;
  561.         }
  562.  
  563.     sort(lastsort);
  564.     first = 0;
  565.     scrprt(NUMLINES,top);
  566.  
  567.     PathName(lock, buf1);
  568.     sprintf(buf,"%s   Files = %ld", buf1, numfiles);
  569.     strncpy(titlestr,buf,80L);
  570.     SetWindowTitles(winptr, -1L,titlestr);
  571. }
  572.  
  573. OpenConsole()
  574. {
  575.         if (OpenDevice("console.device",-1L,&ConsoleReq,0L)){
  576.                 DisplayBeep();
  577.                 Cleanup();
  578.         }
  579.         ConsoleDevice = ConsoleReq.io_Device; /* Lib base address */
  580. }
  581.  
  582. /* this little guy takes input from the IDCMP and stuffs it out to the
  583.         routines involved... */
  584.  
  585. getkey(message) 
  586. struct IntuiMessage *message; 
  587.                 /* this routine has the potential to grow to enormous */
  588. {               /* size... I'll try to restrain myself */
  589.         long keycodes,i,rc;
  590.         char buf[1000];
  591.  
  592.         RawKeyEvent.ie_Code = message->Code;
  593.         RawKeyEvent.ie_Qualifier = message->Qualifier;
  594.         RawKeyEvent.ie_position.ie_addr = *((APTR *)message->IAddress);
  595.         keycodes = RawKeyConvert(&RawKeyEvent,KeyBuffer,BUFSIZ,NULL);
  596.  
  597.         ReplyMsg(message);
  598.  
  599.         if (keycodes > 0){      /* we have something */ 
  600.  
  601.         blankcur();
  602.   
  603.         switch (KeyBuffer[0]) {
  604.             case 0x7f:              /* here we got a delete */
  605.                     KeyBuffer[0] = 0;
  606.                     if (collum == 0)
  607.                         conline[0] = 0;
  608.                     for(i=collum;i<254;i++)
  609.                         conline[i] = conline[i+1];
  610.                     drawline(collum,TRUE);
  611.                     break;
  612.             case 0x08:              /* back space */
  613.                     KeyBuffer[0] = 0;
  614.                     if (collum == 0)
  615.                             conline[0] = 0;
  616.                     if (collum > 0) {
  617.                             collum--;
  618.                             for(i=collum;i<254;i++)
  619.                                     conline[i] = conline[i+1];
  620.                     }
  621.                     drawline(collum, TRUE);
  622.                     break;
  623.             case 0x0d:
  624.                     KeyBuffer[0] = 0;
  625.                     DoDOS(conline);     /* This is the Biggie! */
  626.                     if ( row == NLMO ) {
  627.                             if ( top + NUMLINES < numfiles ) {
  628.                                     line++;
  629.                                     scrprt(NUMLINES,++top);
  630.                             }
  631.                             else
  632.                                     DisplayBeep(0L);
  633.                     }
  634.                     first = 0;
  635.                     collum = 0;
  636.                     for(i=0;i<255;i++)
  637.                             conline[i] = 0;
  638.                     break;
  639.             case 0x9b:
  640.                     KeyBuffer[0] = 0;
  641.                     switch (KeyBuffer[1]) {
  642.                         case 0x3f:        /* looking for the Help key */
  643.                             if (KeyBuffer[2] == 0x7e)
  644.                                 Help();
  645.                             break;
  646.                         case 0x41:      /* up arrow */
  647.                             if (collum == 0) {
  648.                                 for(i=0;i<255;i++)
  649.                                     conline[i] = 0;
  650.                             }
  651.                             else {
  652.                                 strcpy(buf,conline);
  653.                                 conline[first] = 0;
  654.                                 drawline(collum,TRUE);
  655.                                 strcpy(conline,buf);
  656.                             }
  657.                             if (row > 0) {
  658.                                 line--;
  659.                                 row--;
  660.                             }
  661.                             else if (row == 0 && top > 0) {
  662.                                 line--;
  663.                                 scrprt(NUMLINES,--top);
  664.                             }
  665.                             drawline(collum,TRUE);
  666.                             break;
  667.                         case 0x42:      /* Down Arrow */
  668.                             if (collum == 0) {
  669.                                 for(i=0;i<255;i++)
  670.                                     conline[i] = 0;
  671.                             }
  672.                             else {
  673.                                 strcpy(buf,conline);
  674.                                 conline[first] = 0;
  675.                                 drawline(collum,TRUE);
  676.                                 strcpy(conline,buf);
  677.                             }
  678.                             if (row < NLMO) {
  679.                                 if (line < numfiles - 1){
  680.                                     line++;
  681.                                     row++;
  682.                                 }        
  683.                             }
  684.                             else if (row == NLMO && line < numfiles - 1) {
  685.                                 line++;
  686.                                 scrprt(NUMLINES,++top);
  687.                             }
  688.                             drawline(collum,TRUE);
  689.                             break;
  690.                         case 0x44:      /* Left Arrow */
  691.                             if (collum > 0)
  692.                                 collum--;
  693.                                 drawline(collum,TRUE);
  694.                             break;
  695.                         case 0x43:      /* Right Arrow */
  696.                             if (collum < 90)
  697.                                 collum++;
  698.                             else 
  699.                                 DisplayBeep(NULL);
  700.                             drawline(collum,FALSE);
  701.                             break;
  702.                         default:
  703.                             check_for_shift();
  704.                             break;
  705.                     }
  706.                     KeyBuffer[1] = 0;
  707.                     break;
  708.             case 0x1b:      /* The File name insertion thing... */
  709.                     insert_name();
  710.                     break;
  711.             default:
  712.                     if (KeyBuffer[0] < 0x20)
  713.                         control_keys(KeyBuffer[0]);
  714.                     else
  715.                         enter_char(KeyBuffer[0]);
  716.                     break;
  717.             }
  718.     drawcur();
  719.     }
  720. }
  721.  
  722. /* I split up the switch for two reasons... One, I though that the first
  723.    was getting a bit big, Two, I think MANX chokes on large switches.
  724. */
  725.  
  726. /* Looking for the shift-arrow keys */
  727.  
  728. check_for_shift()
  729. {
  730.     char buf[256];
  731.  
  732.     switch (KeyBuffer[1]) {
  733.  
  734.         case 'T':
  735.             if (top > 0) {
  736.  
  737.                 if (line < 10)
  738.                     line = 0;
  739.                 else
  740.                     if (top < 10)
  741.                         line -= top;
  742.                     else 
  743.                         line -= 10;
  744.  
  745.                 if (top < 10)
  746.                     top = 0;
  747.                 else 
  748.                     top -= 10;
  749.  
  750.             }
  751.             scrprt(NUMLINES,top);
  752.             strcpy(buf,conline);
  753.             conline[first] = 0;
  754.             drawline(collum,TRUE);
  755.             strcpy(conline,buf);
  756.             drawline(collum,TRUE);
  757.             break;
  758.  
  759.         case 'S':
  760.  
  761.             if (numfiles - 11 > line) {
  762.  
  763.                 if (numfiles - 11 < line)
  764.                     line = numfiles - 1;
  765.                 else
  766.                     line += 10;
  767.  
  768.                 if (top+10 > numfiles - 1)
  769.                     top = numfiles - 1;
  770.                 else 
  771.                     top += 10;
  772.             }
  773.             scrprt(NUMLINES,top);
  774.             strcpy(buf,conline);
  775.             conline[first] = 0;
  776.             drawline(collum,TRUE);
  777.             strcpy(conline,buf);
  778.             drawline(collum,TRUE);
  779.             break;
  780.         case ' ':
  781.             switch(KeyBuffer[2]) {
  782.                 case 'A':           /* left arrow */
  783.                     collum = 0;
  784.                     first = 0;
  785.                     drawline(collum,TRUE);
  786.                     break;
  787.                 case '@':           /* right arrow */
  788.                     collum = strlen(conline);
  789.                     first = collum > 29 ? collum - 29: 0;
  790.                     drawline(collum,TRUE);
  791.                     break;
  792.             }
  793.         }
  794. }
  795.  
  796. control_keys(key)
  797. char key;
  798. {
  799.     char buf[256];
  800.     int i;
  801.  
  802.     switch(key) {
  803.  
  804.         case 0x01:              /* ^A - get the Arp file-requestor */
  805.             if (Wbargs() == 0){
  806.                 UnLock(olddir);
  807.                 refresh();
  808.             }
  809.             break;
  810.  
  811.         case 0x03:              /* user typed ^C */
  812.             _abort();
  813.             break;
  814.  
  815.         case 0x04:              /* ^D - change directory to fname */
  816.  
  817. /* ***** Hidden SECRET of AmigaDOS !! *****
  818.    only found in the RKM includes... You can tell if a file is
  819.    really a file or if it is a directory by the value of DirEntryType.
  820.    If it is < 0 then it is a file, if > 0 then it is a directory */
  821.  
  822.             if (*finfo[line][0] < 0){
  823.                 sprintf(buf,"%s Not a directory",fname[line]);
  824.                 auto_req(buf);
  825.             }else {
  826.                 changedir(fname[line]);
  827.                 refresh();
  828.             }
  829.             break;
  830.  
  831.         case 0x07:              /* ^G - Re-get the current dir */
  832.             getdir();
  833.             refresh();
  834.             break;
  835.  
  836.         case 0x0b:              /* ^K - Delete file */
  837.             kill(fname[line]);
  838.             refresh();
  839.             break;
  840.  
  841.         case 0x0c:              /* ^L - refresh the screen */
  842.             collum = 0;
  843.             row = 0;
  844.             line = 0;
  845.             first = 0;
  846.             top = 0;
  847.             refresh();          /* also resets the cursor to zero pos */
  848.             break;
  849.  
  850.         case 0x0e:              /* ^N - Make directory */
  851.             make_dir();
  852.             refresh();
  853.             break;
  854.  
  855.         case 0x0f:              /* ^O - sort by pattern */
  856.             sort(3);
  857.             refresh();
  858.             break;
  859.  
  860.         case 0x10:              /* ^P - change directory to Parent */
  861.             parent();
  862.             refresh();
  863.             break;
  864.  
  865.         case 0x12:              /* ^R - rename file */
  866.             rename_file(fname[line]);
  867.             refresh();
  868.             break;
  869.  
  870.         case 0x13:              /* ^S - sort by names */
  871.             sort(0);
  872.             refresh();
  873.             break;
  874.  
  875.         case 0x14:              /* ^T - sort by Time */
  876.             sort(2);
  877.             refresh();
  878.             break;
  879.  
  880.         case 0x15:              /* ^U - erase line to start */
  881.             for (i=0;i<254;i++)
  882.                 conline[i] = '\0';
  883.             first = 0;
  884.             collum = 0;
  885.             drawline(collum,TRUE);
  886.             break;
  887.  
  888.         case 0x18:              /* ^X - Start REXX macro */
  889.             dorexx();
  890.             break;
  891.  
  892.         case 0x19:              /* ^Y - sort by day */
  893.             sort(4);
  894.             refresh();
  895.             break;
  896.  
  897.         case 0x1a:              /* ^Z - sort by size */
  898.             sort(1);
  899.             refresh();
  900.             break;
  901.     }
  902. }
  903.  
  904.  
  905. /* Enter a char into the array and screen */
  906.  
  907. enter_char(c)
  908. register char c;
  909. {
  910.     int i;
  911.     
  912.     for(i=254;i>collum;i--)     /* This is for insert mode */
  913.         conline[i] = conline[i-1];
  914.  
  915.     KeyBuffer[0] = c;
  916.     if (collum < 90) {
  917.             conline[collum] = c;
  918.             collum++;
  919.             drawline(collum,FALSE);
  920.     } else 
  921.             DisplayBeep(NULL);
  922.     KeyBuffer[0] = 0;
  923. }
  924.  
  925. /* Draw the current line from the cursor position, for scrolling */
  926.  
  927. drawline (curpos,flag)
  928. long curpos,flag;
  929. {
  930.         long i,temp1,temp2;
  931.         char tbuf[31];
  932. #ifdef DEBUG
  933.         char buf[90];
  934.  
  935.         sprintf(buf," Row %ld Collumn %ld Top %ld First %ld line %ld \
  936.             numfiles %ld",row,collum,top,first,line,numfiles);
  937.         SetWindowTitles(winptr,-1L,buf);
  938. #endif
  939.  
  940.         temp2 = LINEH * row + TOP + 2;
  941.  
  942.         if ((collum >= first+30) || (collum == first)) {
  943.  
  944.                 if (flag){
  945.                         if (first>0)
  946.                                 first--;
  947.                 }
  948.                 else {
  949.                         if (first<89)
  950.                                 first++;
  951.                 }
  952.         }
  953.     
  954.     strncpy(tbuf,&conline[first],30);
  955.  
  956.     temp1 = strlen(tbuf);
  957.     for(i=temp1;i<29;i++)
  958.         tbuf[i] = ' ';
  959.  
  960.     tbuf[29] = '\0';
  961.  
  962.     input.IText = tbuf;
  963.     PrintIText(rp,&input,(LONG)LEFT,temp2);
  964.     input.IText = KeyBuffer;
  965. }
  966.  
  967. long getcol()
  968. {
  969.         register long temp1;
  970.  
  971.         if (collum == first + 29)
  972.                 temp1 = CHARW * 29 + LEFT;
  973.         else if (first == collum)
  974.                 temp1 = LEFT;
  975.         else {
  976.                 temp1 = CHARW * (collum - first) + LEFT;
  977.         }
  978.         return temp1;
  979. }
  980.  
  981. /* Draw the cursor at the current row & collum */
  982.  
  983. drawcur()
  984. {
  985.         register long temp1,temp2;
  986.  
  987.         temp1 = getcol();
  988.         temp2 = LINEH * row + TOP + 2;
  989.  
  990.         SetDrMd(rp,COMPLEMENT|JAM1);
  991.         SetAPen(rp,4);
  992.         RectFill(rp,temp1,temp2,temp1+7,temp2+7);
  993.         SetAPen(rp,2);
  994.         SetDrMd(rp,JAM1);
  995. }
  996.  
  997. /* Blank the cursur, where-ever it is. */
  998.  
  999. blankcur()
  1000. {
  1001.         register long temp1,temp2;
  1002.                 
  1003.         temp1 = getcol();
  1004.         temp2 = LINEH * row + TOP + 2;
  1005.  
  1006.         SetDrMd(rp,COMPLEMENT|JAM2);
  1007.         SetAPen(rp,0);
  1008.         RectFill(rp,temp1,temp2,temp1+7,temp2+7);
  1009.         SetAPen(rp,2);
  1010.         SetDrMd(rp,JAM1); 
  1011. }
  1012.  
  1013. /* This is where the File insertion code is (in case you were wondering) */
  1014.  
  1015. insert_name()
  1016. {
  1017.         register int i, j;
  1018.         register char *temp;        
  1019.         j=0;
  1020.         
  1021.         if(line > numfiles)
  1022.                 return;
  1023.                 
  1024.         for (i=collum;i<89;i++){
  1025.                 temp = fname[line];
  1026.                 if (temp[j] == 0)
  1027.                         break;
  1028.                 enter_char(temp[j++]);
  1029.         }
  1030. }
  1031. SHAR_EOF
  1032. #    End of shell archive
  1033. exit 0
  1034. -- 
  1035. Bob Page, U of Lowell CS Dept.  page@swan.ulowell.edu  ulowell!page
  1036. Have five nice days.
  1037.